cc.Class({
	extends: cc.Component,

	properties: {},

	onLoad() {},

	start() {
		// cc.log(cc.vv.PlayerInfo);
		// this.num = 1;
		// this.num++;
		// cc.log(this.num);
		this.honeyBunny();
		this.scheduleOnce(this.loadLsattr, 3);
	},

	// update (dt) {},

	// 获取进入房间的玩家信息并显示
	honeyBunny() {
		if (cc.vv.RoomInfo) {
			cc.vv.RoomInfo.forEach((e) => {
				if (e.accountID !== cc.vv.PlayerInfo.accountID) {
					this.node
						.gbn("gameLayer")
						.gbn("PopTishiWhite")
						.gbn("nameLabel")
						.gc(cc.Label).string = e.accountID;
				}
			});
		}
		this.node
			.gbn("gameLayer")
			.gbn("PopTishiBlack")
			.gbn("nameLabel")
			.gc(cc.Label).string = cc.vv.PlayerInfo.accountID;
		let that = this;
		cc.vv.ServerCallBack.refreshRoom = function (data) {
			data.forEach((e) => {
				if (e.accountID !== cc.vv.PlayerInfo.accountID) {
					that.node
						.gbn("gameLayer")
						.gbn("PopTishiWhite")
						.gbn("nameLabel")
						.gc(cc.Label).string = e.accountID;
				} else {
					cc.vv.PlayerInfo = e;
				}
			});
		};
		if (cc.vv.RoomInfo) {
			cc.vv.RoomInfo.forEach((e) => {
				if (e.accountID === cc.vv.PlayerInfo.accountID) {
					if (e.color === "white") {
						this.node
							.gbn("gameLayer")
							.gbn("upIcon")
							.gbn("white").active = false;
						this.node
							.gbn("gameLayer")
							.gbn("downIcon")
							.gbn("black").active = false;
					}
				}
			});
		}
	},

	// 加载页面缩放
	loadLsattr() {
		this.node.getChildByName("loadLayer").runAction(
			cc.sequence(
				cc.scaleTo(0.4, 0),
				cc.callFunc(() => {
					this.node.getChildByName("loadLayer").active = false;
				})
			)
		);
	},
});
